﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using X23.Model;
using X23.Util.LinqUtil;

namespace X23.EFCore.Service
{
    public interface ICRUDService<TDto, T>
        where TDto : class
        where T : BaseAuditedEntity
    {
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<TDto> AddAsync(TDto entity);
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<TDto> UpdateAsync(TDto entity);
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="id">实体模型</param>
        /// <param name="isCommit">是否物理删除（默认否）</param>
        Task<bool> DeleteAsync(object id, bool isPhysicalDelete = false);
        /// <summary>
        /// 获取一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<TDto> GetByIdAsync(object id);
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="predicate"></param>
        /// <param name="advancedSortList">自定义排序</param>
        /// <returns></returns>
        Task<List<TDto>> GetListAsync(Expression<Func<T, bool>> predicate, List<AdvancedSort> advancedSortList = null);
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="predicate"></param>
        /// <param name="pages">页码</param>
        /// <param name="rows">行数</param>
        /// <param name="advancedSortList">自定义排序</param>
        /// <returns></returns>
        Task<PageData<TDto>> GetPageDataAsync(Expression<Func<T, bool>> predicate, int pages, int rows, List<AdvancedSort> advancedSortList = null);
    }
}
